package org.example.factory;

import org.example.userToContentEnum.CounterEnum;
import org.example.factory.bean.CommentCounter;
import org.example.factory.bean.LikeCounter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @FileName CounterFactory
 * @Description
 * @Author coderfun
 * @selfDesc coding in fun
 * @date 2024-11-02
 **/
@Component
public class CounterFactory {

    private final ApplicationContext applicationContext;

    @Autowired
    public CounterFactory(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public Counter getKindOfCounter(String kind) {
        if (kind.equals(CounterEnum.COMMENT.getName())) {
            return applicationContext.getBean(CommentCounter.class);
        } else if (kind.equals(CounterEnum.LIKE.getName())) {
            return applicationContext.getBean(LikeCounter.class);
        }
        return null;
    }
}